home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / pinfocom_3_0.lha / Source / object.c < prev    next >
C/C++ Source or Header  |  1992-10-22  |  4KB  |  226 lines

  1. /* object.c
  2.  *
  3.  *  ``pinfocom'' -- a portable Infocom Inc. data file interpreter.
  4.  *  Copyright (C) 1987-1992  InfoTaskForce
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; see the file COPYING.  If not, write to the
  18.  *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * $Header: RCS/object.c,v 3.0 1992/10/21 16:56:19 pds Stab $
  23.  */
  24.  
  25. #include "infocom.h"
  26.  
  27. static void
  28. pr_obj A1(word, obj_num)
  29. {
  30.     print_str(print_hnum(obj_num));
  31.     print_str(":\"");
  32.     p_obj(obj_num);
  33.     print_char('"');
  34. }
  35.     
  36. static void
  37. cut_obj A2(object_t *, obj, word, obj_num)
  38. {
  39.     object_t *op;
  40.  
  41.     if (obj->parent == 0)
  42.         return;
  43.  
  44.     op = obj_addr(obj->parent);
  45.  
  46.     if (op->child == obj_num)
  47.         op->child = obj->sibling;
  48.     else
  49.     {
  50.         op = obj_addr(op->child);
  51.         while (op->sibling != obj_num)
  52.             op = obj_addr(op->sibling);
  53.         op->sibling = obj->sibling;
  54.     }
  55.     obj->parent = 0;
  56.     obj->sibling = 0;
  57. }
  58.  
  59. void
  60. transfer A2(word, o1, word, o2)
  61. {
  62.     object_t  *obj1;
  63.     object_t  *obj2;
  64.  
  65.     obj1 = obj_addr(o1);
  66.     obj2 = obj_addr(o2);
  67.  
  68.     cut_obj(obj1, o1);
  69.  
  70.     obj1->sibling = obj2->child;
  71.     obj1->parent  = o2;
  72.     obj2->child   = o1;
  73.  
  74.     if (gflags.pr_xfers)
  75.     {
  76.         print_char((word)'[');
  77.         pr_obj(o1);
  78.         print_str(" -> ");
  79.         pr_obj(o2);
  80.         print_char((word)']');
  81.  
  82.         new_line();
  83.     }
  84. }
  85.  
  86. void
  87. remove_obj A1(word, obj_num)
  88. {
  89.     object_t  *obj;
  90.  
  91.     obj = obj_addr(obj_num);
  92.     cut_obj(obj, obj_num);
  93.  
  94.     if (gflags.pr_xfers)
  95.     {
  96.         print_char((word)'[');
  97.         pr_obj(obj_num);
  98.         print_str(" -> (limbo)]");
  99.         new_line();
  100.     }
  101. }
  102.  
  103. void
  104. test_attr A2(word, obj_num, word, attr)
  105. {
  106.     object_t    *obj;
  107.     int         b;
  108.     int         i;
  109.  
  110.     obj = obj_addr(obj_num);
  111.     b = 0x80;
  112.     for (i = attr % 8; i > 0; --i)
  113.         b >>= 1;
  114.  
  115.     if (gflags.pr_atest)
  116.     {
  117.         print_char((word)'[');
  118.         pr_obj(obj_num);
  119.         print_char((word)'(');
  120.         print_num(attr);
  121.         print_str(") == ");
  122.         if (obj->attributes[attr / 8] & b)
  123.             print_str("ON");
  124.         else
  125.             print_str("OFF");
  126.         print_char((word)']');
  127.         new_line();
  128.     }
  129.  
  130.     ret_value((obj->attributes[attr / 8] & b) != 0);
  131. }
  132.  
  133. void
  134. set_attr A2(word, obj_num, word, attr)
  135. {
  136.     object_t    *obj;
  137.     int         b;
  138.     int         i;
  139.  
  140.     obj = obj_addr(obj_num);
  141.     b = 0x80;
  142.     for (i = attr % 8; i > 0; --i)
  143.         b >>= 1;
  144.     obj->attributes[attr / 8] |= b;
  145.  
  146.     if (gflags.pr_attr)
  147.     {
  148.         print_char((word)'[');
  149.         pr_obj(obj_num);
  150.         print_char((word)'(');
  151.         print_num(attr);
  152.         print_str(") := ON");
  153.         print_char((word)']');
  154.         new_line();
  155.     }
  156. }
  157.  
  158. void
  159. clr_attr A2(word, obj_num, word, attr)
  160. {
  161.     object_t    *obj;
  162.     int         b;
  163.     int         i;
  164.  
  165.     obj = obj_addr(obj_num);
  166.     b = 0x80;
  167.     for (i = attr % 8; i > 0; --i)
  168.         b >>= 1;
  169.     obj->attributes[attr / 8] &= (~b);
  170.  
  171.     if (gflags.pr_attr)
  172.     {
  173.         print_char((word)'[');
  174.         pr_obj(obj_num);
  175.         print_char((word)'(');
  176.         print_num(attr);
  177.         print_str(") := OFF");
  178.         print_char((word)']');
  179.         new_line();
  180.     }
  181. }
  182.  
  183. void
  184. get_loc A1(word, obj_num)
  185. {
  186.     object_t *obj;
  187.  
  188.     obj = obj_addr(obj_num);
  189.     store((word)obj->parent);
  190. }
  191.  
  192. void
  193. get_holds A1(word, obj_num)
  194. {
  195.     object_t *obj;
  196.  
  197.     obj = obj_addr(obj_num);
  198.     store((word)obj->child);
  199.     ret_value(obj->child != 0);
  200. }
  201.  
  202. void
  203. get_link A1(word, obj_num)
  204. {
  205.     object_t *obj;
  206.  
  207.     obj = obj_addr(obj_num);
  208.     store((word)obj->sibling);
  209.     ret_value(obj->sibling != 0);
  210. }
  211.  
  212. void
  213. check_loc A2(word, o1, word, o2)
  214. {
  215.     object_t *obj;
  216.  
  217.     obj = obj_addr(o1);
  218.     ret_value(obj->parent == o2);
  219. }
  220.  
  221. object_t *
  222. obj_addr A1(word, obj_num)
  223. {
  224.     return (object_t *)(objd.obj_base+(obj_num*objd.obj_size)+objd.obj_offset);
  225. }
  226.